package servizio;

public class ValidaInput {

	public static boolean validaRegistrazione(String nome){
		char[] chars = nome.toCharArray();
		for(int i=0;i<chars.length;i++){
			char currChar = chars[i];
			if(!isLettera(currChar) && !isNumero(currChar)){
				return false;
			}
		}
		return true;
	}
	
	public static String adeguaNome(String nome){
		char[] chars = nome.toCharArray();
		String out="";
		for(int i=0;i<chars.length;i++){
			char currChar = chars[i];
			if(isLettera(currChar) || isNumero(currChar)){
				out+= String.valueOf(currChar);
			}
		}
		return out;
	}
	
	static private boolean isLettera(char car){
		
		if((car>=65 && car<=90) || (car>=97 && car<=122))
			return true;
		
		return false;
	}
	
	static private boolean isNumero(char car){
		
		if((car>=48 && car<=57))
			return true;
		
		return false;
	}
	
	public static String adeguaTelefono(String telefono){
		
		char[] chars = telefono.toCharArray();
		String out="";
		for(int i=0;i<chars.length;i++){
			char currChar = chars[i];
			if(isNumero(currChar)){
				out+= String.valueOf(currChar);
			}
		}
		return out;
	}
}
